package app.beit.finportal.service;


import org.springframework.beans.factory.annotation.Autowired;

import app.beit.finportal.bean.MSConfigBean;
import app.beit.finportal.config.MasterConfig;
import app.beit.finportal.dao.MSConfigDao;
import app.beit.finportal.entity.MSConfig;
import app.beit.finportal.service.convert.MSConfigConvert;

public class MSConfigService {
	
	private final String IS_INTERNET = "IS_INTERNET";
	private final String FILE_DOWNLOAD_LOCATION = "FILE_DOWNLOAD_LOCATION";

	@Autowired
	private MSConfigDao msconfigDao;
	
	public MSConfigBean getIsInternet() throws Exception{
		final MSConfigBean bean = MasterConfig.getInstance().getDeployBean();
		if(bean != null){
			return bean;
		}

		final MSConfig entitie = this.msconfigDao.getByName(IS_INTERNET);
		if(entitie != null){
			final MSConfigBean config = MSConfigConvert.entityToBean(entitie);
			MasterConfig.getInstance().setDeployBean(config);
			return config;
		}
		
		return null;
	}

	public MSConfigBean getFileLocation() throws Exception{
		final MSConfigBean bean = MasterConfig.getInstance().getFileLocationBean();
		if(bean != null){
			return bean;
		}

		final MSConfig entitie = this.msconfigDao.getByName(FILE_DOWNLOAD_LOCATION);
		if(entitie != null){
			final MSConfigBean config = MSConfigConvert.entityToBean(entitie);
			MasterConfig.getInstance().setFileLocationBean(config);
			return config;
		}
		
		return null;
	}
	
}
